<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<ui:composition template="/resources/template/template.xhtml">

	<ui:define name="title">
		<h:outputText value="Administration des news" />
	</ui:define>

	<ui:define name="content">

		<h:form>
			<p:panel styleClass="panel-bouton">
				<p:commandButton icon="ui-icon-circle-plus" action="#{administrationNewsBean.initNouvelleNews()}" update="@widgetVar(_dialogModificationNews)" />
			</p:panel>
			<p:dataTable widgetVar="_datatableNews" value="#{administrationNewsBean.listeNews}" var="news" rowKey="#{news.id}" selectionMode="single" selection="#{administrationNewsBean.news}" scrollable="true" scrollHeight="500" emptyMessage="Aucune news">
				<p:ajax event="rowSelect" listener="#{administrationNewsBean.selectionNews}" update="@widgetVar(_dialogModificationNews)" />
				<p:column>
					<f:facet name="header">
						<h:outputText value="TITRE" />
					</f:facet>
					<h:outputText value="#{news.titre}" />
				</p:column>
				<p:column>
					<f:facet name="header">
						<h:outputText value="DATE CREATION" />
					</f:facet>
					<h:outputText value="#{news.dateCreation}">
						<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
					</h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">
						<h:outputText value="UTILISATEUR" />
					</f:facet>
					<h:outputText value="#{news.utilisateur.nomPrenom}" />
				</p:column>
			</p:dataTable>
		</h:form>

	</ui:define>

	<ui:define name="dialog">

		<h:form>
			<p:dialog widgetVar="_dialogModificationNews" modal="true" dynamic="true" resizable="false" closeOnEscape="true" showEffect="fade" onHide="PF('_dialogModificationNews').initPosition()">
				<f:facet name="header">
					<h:outputText value="News en #{administrationNewsBean.typeModification}" />
				</f:facet>
				<h:panelGrid columns="2">
					<p:outputLabel value="Titre" for="idInputTitre" />
					<p:inputText id="idInputTitre" value="#{administrationNewsBean.news.titre}" size="50" />
					<p:outputLabel value="Contenu" for="idEditorContenu" />
					<p:editor id="idEditorContenu" widgetVar="_editorContenu" value="#{administrationNewsBean.news.contenu}" styleClass="width-100pct" />
				</h:panelGrid>
				<f:facet name="footer">
					<p:outputPanel autoUpdate="true" styleClass="align-right">
						<p:commandButton value="Effacer le contenu" icon="ui-icon-close" oncomplete="PF('_editorContenu').clear()" immediate="true" />
						<p:commandButton value="Annuler" icon="ui-icon-close" oncomplete="PF('_dialogModificationNews').hide()" immediate="true" />
						<p:commandButton value="Valider" icon="ui-icon-disk" action="#{administrationNewsBean.valider()}" update="@widgetVar(_datatableNews)" />
					</p:outputPanel>
				</f:facet>
			</p:dialog>
		</h:form>

	</ui:define>

</ui:composition>
</html>